// pages/dingdan/dingdan.js
import {
    request
} from "../../request/request";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orders: [{
                "order_id": 428,
                "user_id": 23,
                "order_number": "HMDD20190802000000000428",
                "order_price": 13999,
                "order_pay": "0",
                "is_send": "否",
                "trade_no": "",
                "order_fapiao_title": "个人",
                "order_fapiao_company": "",
                "order_fapiao_content": "",
                "consignee_addr": "广东省广州市海珠区新港中路397号",
                "pay_status": "1",
                "create_time": 1681121111,
                "update_time": 1564731518,
                "order_detail": null,
                "goods": [{
                    "id": 717,
                    "order_id": 428,
                    "goods_id": 43986,
                    "goods_price": 13999,
                    "goods_number": 1,
                    "goods_total_price": 13999,
                    "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
                    "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
                }],
                "total_count": 1,
                "total_price": 13999
            },
            {
                "order_id": 429,
                "user_id": 23,
                "order_number": "HMDD20190802000000000428",
                "order_price": 13999,
                "order_pay": "0",
                "is_send": "否",
                "trade_no": "",
                "order_fapiao_title": "个人",
                "order_fapiao_company": "",
                "order_fapiao_content": "",
                "consignee_addr": "广东省广州市海珠区新港中路397号",
                "pay_status": "1",
                "create_time": 1681121111,
                "update_time": 1564731518,
                "order_detail": null,
                "goods": [{
                    "id": 717,
                    "order_id": 428,
                    "goods_id": 43986,
                    "goods_price": 13999,
                    "goods_number": 1,
                    "goods_total_price": 13999,
                    "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
                    "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
                }],
                "total_count": 1,
                "total_price": 13999
            },
            {
                "order_id": 430,
                "user_id": 23,
                "order_number": "HMDD20190802000000000428",
                "order_price": 13999,
                "order_pay": "0",
                "is_send": "否",
                "trade_no": "",
                "order_fapiao_title": "个人",
                "order_fapiao_company": "",
                "order_fapiao_content": "",
                "consignee_addr": "广东省广州市海珠区新港中路397号",
                "pay_status": "1",
                "create_time": 1681121111,
                "update_time": 1564731518,
                "order_detail": null,
                "goods": [{
                    "id": 717,
                    "order_id": 428,
                    "goods_id": 43986,
                    "goods_price": 13999,
                    "goods_number": 1,
                    "goods_total_price": 13999,
                    "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
                    "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
                }],
                "total_count": 1,
                "total_price": 13999
            },
            {
                "order_id": 431,
                "user_id": 23,
                "order_number": "HMDD20190802000000000428",
                "order_price": 13999,
                "order_pay": "0",
                "is_send": "否",
                "trade_no": "",
                "order_fapiao_title": "个人",
                "order_fapiao_company": "",
                "order_fapiao_content": "",
                "consignee_addr": "广东省广州市海珠区新港中路397号",
                "pay_status": "1",
                "create_time": 1681121111,
                "update_time": 1564731518,
                "order_detail": null,
                "goods": [{
                    "id": 717,
                    "order_id": 428,
                    "goods_id": 43986,
                    "goods_price": 13999,
                    "goods_number": 1,
                    "goods_total_price": 13999,
                    "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
                    "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
                }],
                "total_count": 1,
                "total_price": 13999
            },
            {
                "order_id": 432,
                "user_id": 23,
                "order_number": "HMDD20190802000000000428",
                "order_price": 13999,
                "order_pay": "0",
                "is_send": "否",
                "trade_no": "",
                "order_fapiao_title": "个人",
                "order_fapiao_company": "",
                "order_fapiao_content": "",
                "consignee_addr": "广东省广州市海珠区新港中路397号",
                "pay_status": "1",
                "create_time": 1681121111,
                "update_time": 1564731518,
                "order_detail": null,
                "goods": [{
                    "id": 717,
                    "order_id": 428,
                    "goods_id": 43986,
                    "goods_price": 13999,
                    "goods_number": 1,
                    "goods_total_price": 13999,
                    "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统",
                    "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg"
                }],
                "total_count": 1,
                "total_price": 13999
            }
        ],
        tabs: [{
                id: 0,
                value: "全部",
                isActive: true
            },
            {
                id: 1,
                value: "代付款",
                isActive: false
            },
            {
                id: 2,
                value: "待发货",
                isActive: false
            },
            {
                id: 3,
                value: "退款/退货",
                isActive: false
            }
        ],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    async onLoad(options) {
        let tabs = this.data.tabs
        // index数组的下标
        tabs.forEach((item, index) => {
            if (index == options.type) {
                item.isActive = true
            } else {
                item.isActive = false
            }
        })
        this.setData({
            tabs
        })
        //必须是企业号 才能拿到token 没授权就没有数据 所以用了死的数据
        const token = wx.getStorageSync("token");
        let header = "值"
        console.log(token);
        const res = await request({
            url: "https://api-hmugo-web.itheima.net/api/public/v1/my/orders/all",
            data: 1,
            header
        })
        this.getorders()

    },
    getorders() {
        let orders = this.data.orders.map((item) => {
            item.create_time = new Date(item.create_time * 1000).toLocaleString()
            return item
        })
        this.setData({
            orders
        })
        console.log(this.data.orders);
    },
    handletabsItemChange(e) {
        // console.log(e);
        // 1 获取被点击的标题索引
            wx.showLoading({
            title: "加载中",
          });
        const {
            index
        } = e.detail;
        // 2 修改源数组
        let {
            tabs
        } = this.data;
        tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
        // 3 赋值到data中
        this.setData({
            tabs
        })
        let ding = setTimeout(function () {
            wx.hideLoading()
        }, 500)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})